@echo off
setlocal enabledelayedexpansion

:: 设置时间戳格式
for /f "tokens=2 delims==" %%I in ('wmic OS Get localdatetime /value') do set datetime=%%I
set timestamp=%datetime:~0,8%_%datetime:~8,6%

:: 创建备份目录
set backupDir=./Backup_%timestamp%
if not exist "!backupDir!" mkdir "!backupDir!"

:: 检查并备份文件
@REM for %%C in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
for %%C in (A B C D E F G H I J K) do (
    set filename=%%C.cpp
    if exist "!filename!" (
        :: 备份文件
        copy "!filename!" "!backupDir!\!filename!_!timestamp!.bak"
        :: 清空原文件
        > "!filename!" (
            type nul
        )
    ) else (
        echo. > !filename!
    )
)

echo Backup and clear operation completed.
endlocal